feat(aiohttp): Apply data_collection filtering to URL query strings#6833
Conversation
…n config `_filter_headers` previously used a hardcoded sensitive-header tuple and a `send_default_pii`/`use_annotated_value` toggle. It now delegates to `_apply_key_value_collection_filtering` from `sentry_sdk.data_collection`, so header scrubbing respects the new `data_collection.http_headers.request` allowlist/denylist/off configuration. Cookie and set-cookie headers are always redacted regardless of mode. Drops the now-unused `use_annotated_value` parameter from all call sites. Work to scrub cookies in a more granular way will be tackled as part of PY-2581/#6741. Fixes PY-2584 Fixes #6744
… _experiments property in the client
…still being needed for the url attribute
…ures The new lambda_functions_with_embedded_sdk fixture directories were missing the .gitignore that the other fixtures use to keep everything except index.py untracked. As a result, certifi and urllib3 packages installed by the test setup got committed, and ruff failed CI linting against them since they're unmodified third-party code. Add the missing .gitignore to each new fixture directory and remove the committed vendored packages; they are regenerated automatically at test time via `uv pip install --target`.
…tarlette, litestar, starlite Extends the granular cookie collection controls (data_collection.cookies) to _wsgi_common, starlette, litestar, and starlite, matching the behavior already used elsewhere. Falls back to should_send_default_pii() when data_collection is not configured for cookies. HTTP "Cookie" and "set-cookie" headers will continue to be completely filtered with the "[Filtered]" value. Fixes PY-2581 Fixes #6741
…de is off Previously the async request extractors attached an empty cookies dict when the data_collection cookies mode was off, while sync route handlers omitted it entirely. Make all integrations consistent by not attaching the cookies field at all when filtering yields no cookies.
…n config `_filter_headers` previously used a hardcoded sensitive-header tuple and a `send_default_pii`/`use_annotated_value` toggle. It now delegates to `_apply_key_value_collection_filtering` from `sentry_sdk.data_collection`, so header scrubbing respects the new `data_collection.http_headers.request` allowlist/denylist/off configuration. Cookie and set-cookie headers are always redacted regardless of mode. Drops the now-unused `use_annotated_value` parameter from all call sites. Work to scrub cookies in a more granular way will be tackled as part of PY-2581/#6741. Fixes PY-2584 Fixes #6744
… _experiments property in the client
…still being needed for the url attribute
…ures The new lambda_functions_with_embedded_sdk fixture directories were missing the .gitignore that the other fixtures use to keep everything except index.py untracked. As a result, certifi and urllib3 packages installed by the test setup got committed, and ruff failed CI linting against them since they're unmodified third-party code. Add the missing .gitignore to each new fixture directory and remove the committed vendored packages; they are regenerated automatically at test time via `uv pip install --target`.
…ntry/sentry-python into py-2584-update-wsgi-filter-headers
…tarlette, litestar, starlite Extends the granular cookie collection controls (data_collection.cookies) to _wsgi_common, starlette, litestar, and starlite, matching the behavior already used elsewhere. Falls back to should_send_default_pii() when data_collection is not configured for cookies. HTTP "Cookie" and "set-cookie" headers will continue to be completely filtered with the "[Filtered]" value. Fixes PY-2581 Fixes #6741
…de is off Previously the async request extractors attached an empty cookies dict when the data_collection cookies mode was off, while sync route handlers omitted it entirely. Make all integrations consistent by not attaching the cookies field at all when filtering yields no cookies.
…into py-2581-cookies
The streaming path no longer emits a client span when there is no current span (#6810), so unpack only the server span.
Filter WSGI request event and span query strings through the data_collection.url_query_params behaviour (denylist/allowlist/off) instead of gating query string capture solely on send_default_pii. This brings WSGI-based integrations in line with the data collection spec's handling of cookies and headers. Rename the data_collection field query_params to url_query_params to match the updated data collection spec, which distinguishes URL query params from other key-value data (cookies, headers). Update the DataCollection/DataCollectionUserOptions TypedDicts, resolution logic in data_collection.py, and all WSGI/Flask/Django test coverage accordingly. Refs PY-2583
…orm with what is shown in the data collection spec
Filter query string parameters in the ASGI request data and span attributes according to the data_collection.url_query_params config, mirroring the existing WSGI behaviour. Falls back to the legacy send_default_pii check when data_collection is not enabled. Refs PY-2583 Refs #6743
Use the new data_collection settings to filter url.query and related span attributes for both the aiohttp server and client integrations, falling back to should_send_default_pii() when data_collection is not configured. Refs PY-2583 Refs #6743
Codecov Results 📊✅ 93960 passed | ⏭️ 6304 skipped | Total: 100264 | Pass Rate: 93.71% | Execution Time: 327m 7s 📊 Comparison with Base Branch
All tests are passing successfully. ✅ Patch coverage is 92.31%. Project has 2478 uncovered lines. Files with missing lines (1)
Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 89.74% 89.75% +0.01%
==========================================
Files 193 193 —
Lines 24149 24167 +18
Branches 8430 8446 +16
==========================================
+ Hits 21670 21689 +19
- Misses 2479 2478 -1
- Partials 1391 1392 +1Generated by Codecov Action |
| url_attributes = {} | ||
| if should_send_default_pii(): | ||
| if has_data_collection_enabled(client.options): | ||
| url_attributes["url.full"] = "%s://%s%s" % ( |
There was a problem hiding this comment.
I know this is just copied from the should_send_default_pii branch, but I've just realized it's wrong: url.full should contain the query and it doesn't.
Probably makes more sense to fix this afterwards, when this stack has been merged. I'll make an issue for it.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 407ad17. Configure here.
| @@ -5,6 +5,9 @@ | |||
| import sentry_sdk | |||
| from sentry_sdk.api import continue_trace | |||
| from sentry_sdk.consts import OP, SPANDATA, SPANSTATUS | |||
There was a problem hiding this comment.
Legacy client span leaks unfiltered query strings when data_collection is configured
The legacy (non-streaming) client span path stores the raw query string without applying _apply_data_collection_filtering_to_query_string, so sensitive parameters bypass the user-configured data_collection filters.
Evidence
_apply_data_collection_filtering_to_query_stringis imported at line 7 for use in the streaming span path.- In the streaming client path (
on_request_start, ~line 400),parsed_url.queryis filtered before being stored inattributes["url.query"]. - In the legacy client
elsebranch at line 428,legacy_span.set_data(SPANDATA.HTTP_QUERY, parsed_url.query)stores the raw, unfiltered query string regardless ofdata_collectionsettings. - The new tests added in
test_aiohttp.py(test_client_url_query_data_collection_span_streaming) only exercise the streaming path withtrace_lifecycle="stream", leaving the legacy path uncovered.
Identified by Warden find-bugs · EJW-8M7

Use the new data_collection settings to filter url.query and related
span attributes for both the aiohttp server and client integrations,
falling back to should_send_default_pii() when data_collection is not
configured.
Refs #6743
Refs #6743